Skip to content

Conversation

@johndpope
Copy link

fellow devs watching PRs do check this - just a few lines of code changes.

Screenshot from 2025-04-07 21-52-26

@johndpope johndpope changed the title 🏂 - rich logging 🏂 - rich logging (provide clarity to downstream devs seeing errors in console) Apr 7, 2025
@city96
Copy link
Contributor

city96 commented Apr 13, 2025

I've had a simpler version of this for a while, which was mostly based on the code from sd_scripts

You need to remove the default logging handler(s) to avoid the double-logging shown in your screenshot.
The code below just works as a custom node and sets up the handler globally when it gets loaded, which is mostly enough for my usecase.

import logging
from rich.console import Console
from rich.logging import RichHandler

if logging.root.handlers:
    for handler in logging.root.handlers[:]:
        logging.root.removeHandler(handler)

formatter = logging.Formatter(fmt="%(message)s", datefmt="%Y-%m-%d %H:%M:%S")
new_handler = RichHandler(console=Console(stderr=True))
new_handler.setFormatter(formatter)
logging.root.addHandler(new_handler)

NODE_CLASS_MAPPINGS = {}

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants